<?php

class PagamentoDao extends Dao {

    public function injectDependencies() {

    }

    public function findAllPaymentsByUser($IDUsuario) {
        $this->initConnection();
        $this->tMysqli->escape($IDUsuario);
        $StSql = TQuery::getSqlFindAllPaymentsByUser($IDUsuario);
        $tQuery = $this->tMysqli->exec($StSql);
        $ArPayments = array();
        while($ArPaymentData = mysqli_fetch_assoc($tQuery)) {
            $ArPayments[] = new Pagamento($ArPaymentData, $this->tMysqli);
        }
        $this->closeConnection();
        return $ArPayments;
    }

    public function releasePayment($IDAdministracao, $ArPayments) {
        $this->initTransaction();
        $this->tMysqli->escape($IDAdministracao);
        $this->tMysqli->escape($ArPayments);
        foreach($ArPayments as $StPeriod => $ArPaymentData) {
            $StSql = TQuery::getSqlInsertUserPayment($IDAdministracao, $StPeriod, $ArPaymentData);
            $this->tMysqli->exec($StSql);
        }
        $this->closeTransaction();
        return $this->tMysqli->lastTransactionReturn();
    }

}

?>
